<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 使用 Promise 实现每隔一秒输出 1、2、3

        function oneTwoThree() {
            const arr = [1, 2, 3];
            arr.reduce((prev, next) => {
                return prev.then(() => {
                    return new Promise(res => {
                        setTimeout(() => {
                            console.log(next);
                            res();
                        }, 1000);
                    })
                })
            }, Promise.resolve())
        }

        oneTwoThree();
    </script>
</body>

</html>